//企业综合信用echarts highcharts
//-----highstock时间设置
Highcharts.setOptions({
    lang: {
        rangeSelectorZoom: "缩放：",
        //                汉化界面
        months: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        shortMonths: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        weekdays: ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
    },
    global: {
        useUTC: false
    }
});
var colors = ['#FE4639', '#FE6F1A', '#CDD313', '#05DB88', '#019fe8'];
var pJson = '{"经营绩效":"performance","经营稳定":"stability","发展能力":"ability","资本实力":"relations","管理团队":"team"}';
var indusJson = '{"农林牧渔":"performance","采矿业":"stability","发展能力":"ability","资本实力":"relations","管理团队":"team"}';
var regionJson = '{"北京":"performance","天津":"stability","发展能力":"ability","资本实力":"relations","管理团队":"team"}';
var drawEcharts = function (alldata, latest_year, year) {
    var detailinfo, nowYear, latest_score;
    if (year) {
        nowYear = year;
    } else {
        nowYear = latest_year;//获取最新一年或者某一年数据
    }
    detailinfo = alldata[nowYear];
    var minscore = 1000,
        maxscore = 300,//历史纪录纵坐标范围确定
        basicinfo = alldata["basic"],//企业基础信息
        total = alldata["total"],
        nowscore, industryIndex, regionIndex;//当前企业最新一年总分数
    //生成echarts图表所需数据格式
    var years = [], historyscore = [],//历史记录年份和总分
        scoresIndicator = [], scoresName = [], scoresValue = [],//各项指标细分分数
        regionTrendName = [], regionTrendValue = [],//地区分布
        industryTrendName = [], industryTrendValue = [];//行业分布
    var getData = function (type) {
        var data = detailinfo[type];
        scoresIndicator = [], scoresName = [], scoresValue = [];//各项指标细分分数
        for (var k in data) {
            scoresName.push(k);
            scoresValue.push(data[k]);
            if (type == "scores") {
                var obj = {name: k, max: 100};
                scoresIndicator.push(obj);
            }
        }
    };
    var getData2 = function (type, name, value) {
        var data = detailinfo[type];
        for (var k in data) {
            name.push(k);
            value.push(data[k]);
        }
        score > maxscore ? maxscore = score : maxscore;
        score < minscore ? minscore = score : maxscore;
    };
    getData("scores", scoresName, scoresValue);
    getData2("industryTrend", industryTrendName, industryTrendValue);
    getData2("regionTrend", regionTrendName, regionTrendValue);
    //历史记录分数
    for (var k in total) {
        var tal = total[k];
        for (var j in tal) {
            var score = tal[j];
            if (j == nowYear) {
                nowscore = score;
            }
            if (j == latest_year) {
                latest_score = score;
            }
            score > maxscore ? maxscore = score : maxscore;
            score < minscore ? minscore = score : maxscore;
            years.unshift(j);
            historyscore.unshift(score);
        }
    }
    //仪表盘图 企业信用总评分的情况
    var c_ratings = echarts.init(document.getElementById('c_ratings'));
    var ratingsoption = {
        tooltip: {
            formatter: '{a} <br/>{b} : {c}'
        },
        toolbox: {},
        series: [
            {
                name: '信用评级',
                type: 'gauge',
                startAngle: '200',
                endAngle: '-20',
                min: 360,
                max: 950,
                splitNumber: '5',
                axisLine: {
                    lineStyle: {
                        color: [[0.2, colors[0]], [0.4, colors[1]], [0.6, colors[2]], [0.8, colors[3]], [1, colors[4]]],
                        width: 10
                    }
                },
                pointer: {
                    length: "70%",
                    width: 2
                },
                splitLine: {
                    length: '10',
                    lineStyle: {
                        width: 0
                    }
                },
                axisTick: {
                    length: '10',
                    lineStyle: {
                        width: 0
                    }
                },
                axisLabel: {
                    show: false
                },
                detail: {formatter: '{value}', offsetCenter: [0, '30%'], textStyle: {fontSize: 16}},
                data: [{value: latest_score}]
            }
        ]
    };
    c_ratings.setOption(ratingsoption);
    //历史信用情况展示 折线图
    var c_history = echarts.init(document.getElementById('c_history'));
    var historyoption = {
        title: {
            show: false
        },
        color: [colors[4]],
        tooltip: {},
        legend: {
            show: false,
            data: ['信用评分']
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {},
        xAxis: {
            type: 'category',
            boundaryGap: true,
            data: years
        },
        yAxis: {
            type: 'value',
            min: minscore - 50,
            max: maxscore + 50
        },
        series: [
            {
                name: '信用评分',
                type: 'line',
                lineStyle: {
                    normal: {
                        width: 1
                    }
                },
                symbolSize: function (value, params) {
                    if (params.name == nowYear) {
                        return 14;
                    } else {
                        return 8;
                    }
                },
                data: historyscore
            }
        ]
    };
    c_history.setOption(historyoption);
    //highcharts各个维度展示 雷达图
    var c_dimensions_high = new Highcharts.Chart({
        chart: {
            renderTo: 'c_dimensions_high',
            polar: true,
            type: 'area',
            events: {
                click: function (event) {
                    var ele = event.srcElement.className.baseVal;
                    var bg = ele.indexOf("highcharts-background");
                    if (bg == -1) {
                        var name = event.srcElement.innerHTML;
                        barClick(name);
                    }
                }
            }
        },
        title: {
            text: '',
            x: -800
        },
        pane: {
            size: '80%'
        },
        xAxis: {
            categories: scoresName,
            tickmarkPlacement: 'on',
            lineWidth: 0
        },
        yAxis: {
            show: false,
            gridLineInterpolation: 'polygon',
            lineWidth: 0,
            min: 0,
            max: 100,
            labels: {
                enabled: false
            }
        },
        tooltip: {
            shared: true,
            pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {point.y}</b>'
        },
        legend: {
            enabled: false
        },
        series: [{
            name: nowYear + "年" + '各个维度评分',
            data: scoresValue,
            pointPlacement: 'on'
        }]
    });
    //各项维度的细分 柱状图
    var c_dimensions_bar = echarts.init(document.getElementById('c_dimensions_bar'));
    var baroption = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            },
            formatter: '{b}: {c}'
        },
        legend: {
            data: [nowYear + "年" + '各个维度评分']
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'value'
        },
        yAxis: {
            type: 'category',
            data: scoresName
        },
        series: [
            {
                name: nowYear + "年" + '各个维度评分',
                type: 'bar',
                label: {
                    normal: {
                        show: true,
                        position: 'insideRight'
                    }
                },
                data: scoresValue
            }
        ]
    };
    c_dimensions_bar.setOption(baroption);
    var c_industry_bar = new Highcharts.Chart({
        chart: {
            renderTo: 'c_industry_bar',
            type: 'area',
            events: {
                click: function (event) {
                    var ele = event.srcElement.className.baseVal;
                    var bg = ele.indexOf("highcharts-area");
                    if (bg != -1) {
                        gotoDetail("industry", "", 0);
                    }
                }
            }
        },
        title: {
            text: ""
        },
        xAxis: {
            categories: industryTrendName
        },
        yAxis: {
            minorGridLineColor: '#E0E0E0',
            tickInterval: '200',
            title: {
                text: ''
            },
            plotLines: [{
                color: colors[0],
                dashStyle: 'solid',
                value: nowscore,
                width: 2,
                label: {
                    useHTML: true,
                    align: "right",
                    text: '<div class="bubble_box"><p class="bubble_text">当前企业</p><span class="bubble">' + nowscore + '</span></div>',
                    y: -20
                },
                events: {
                    mouseover: function () {
                    }
                }
            }]
        },
        plotOptions: {
            series: {
                cursor: 'pointer',
                events: {
                    click: function (e) {
                        var name = e.point.category;
                        var id = jQuery.parseJSON(indusJson)[name];
                        if (id) {
                            gotoDetail("industry", id, 1);
                        } else {
                            gotoDetail("industry", id, 0);
                        }
                    }
                }
            }
        },
        tooltip: {
            pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {point.y}</b>'
        },
        series: [{
            name: nowYear + "年" + '行业信用评分走势',
            data: industryTrendValue
        }]
    });
    var c_region_bar = new Highcharts.Chart({
        chart: {
            renderTo: 'c_region_bar',
            type: 'area',
            events: {
                click: function (event) {
                    var ele = event.srcElement.className.baseVal;
                    var bg = ele.indexOf("highcharts-area");
                    if (bg != -1) {
                        gotoDetail("region", "", 0);
                    }
                }
            }
        },
        title: {
            text: ""
        },
        xAxis: {
            categories: regionTrendName
        },
        yAxis: {
            minorGridLineColor: '#E0E0E0',
            tickInterval: '200',
            title: {
                text: ''
            },
            plotLines: [{
                color: colors[0],
                dashStyle: 'solid',
                value: nowscore,
                width: 2,
                label: {
                    useHTML: true,
                    align: "right",
                    text: '<div class="bubble_box"><p class="bubble_text">当前企业</p><span class="bubble">' + nowscore + '</span></div>',
                    y: -20
                },
                events: {
                    mouseover: function () {
                    }
                }
            }]
        },
        plotOptions: {
            series: {
                cursor: 'pointer',
                events: {
                    click: function (e) {
                        var name = e.point.category;
                        var id = jQuery.parseJSON(regionJson)[name];
                        if (id) {
                            gotoDetail("region", id, 1);
                        } else {
                            gotoDetail("region", id, 0);
                        }
                    }
                }
            }
        },
        tooltip: {
            pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {point.y}</b>'
        },
        series: [{
            name: nowYear + "年" + '企业信用地区分布',
            data: regionTrendValue
        }]
    });
    const n1 = scoresName;
    const v1 = scoresValue;
    const barOpt = c_dimensions_bar.getOption();
    var c_highOpt_dimensions = $('#c_dimensions_high').highcharts();
    var c_highOpt_industry = $('#c_industry_bar').highcharts();
    var c_highOpt_region = $('#c_region_bar').highcharts();
    //柱状
    c_dimensions_bar.on('click', function (params) {
        var name = params.name;
        barClick(name);
    });
    var c_dimensions_bar2;
    var barClick = function (name) {
        c_dimensions_bar2 = echarts.init(document.getElementById('c_dimensions_bar'));
        //五大维度
        var bbool = pJson.includes(name);
        if (bbool) {
            //点击的是五大维度
            var getType = jQuery.parseJSON(pJson)[name];
            if (getType) {
                getData(getType);
                baroption.legend.data = [name];
                baroption.yAxis.data = scoresName;
                //柱状图
                baroption.series[0].name = name;
                baroption.series[0].data = scoresValue;
                c_dimensions_bar2.setOption(baroption);
                //雷达图
                c_highOpt_dimensions.series[0].update({name: name});
                c_highOpt_dimensions.xAxis[0].categories = scoresName;
                c_highOpt_dimensions.series[0].setData(scoresValue);
            }
        } else {
            goBack();
        }
        if (name == "") {
            goBack();
        }
        c_dimensions_bar2.on('click', function (params) {
            var name = params.name;
            barClick(name);
        });
    };
    var goBack = function () {
        //点击的是中间区域
        c_dimensions_bar2.setOption(barOpt);
        //雷达图
        c_highOpt_dimensions.series[0].update({name: nowYear + "年" + "各个维度评分"});
        c_highOpt_dimensions.xAxis[0].categories = n1;
        c_highOpt_dimensions.series[0].setData(v1);
    };
    //历史走势点击
    c_history.on('click', function (params) {
        drawEcharts(alldata, params.name);
    });
    //各行业 地区跳转具体
    var iname = [], ivalue = [], rname = [], rvalue = [];
    var gotoDetail = function (type, id, num) {
        if (num == 1) {
            var zjname = [], zjvalue = [];
            var regionDetail = {
                "海淀区": 765,
                "昌平区": 725,
                "朝阳区": 584,
                "大兴区": 684,
                "密云县": 571,
                "东城区": 620,
                "西城区": 527
            };
            for (var k in regionDetail) {
                zjname.push(k);
                zjvalue.push(regionDetail[k]);
            }
            if (type == "industry") {
                iname = zjname;
                ivalue = zjvalue;
            } else {
                rname = zjname;
                rvalue = zjvalue;
            }
        }
        if (type == "industry") {
            if (num == 1) {
                //跳转具体行业
                c_highOpt_industry.xAxis[0].categories = iname;
                c_highOpt_industry.series[0].setData(ivalue);
            } else {
                //返回大行业
                c_highOpt_industry.xAxis[0].categories = industryTrendName;
                c_highOpt_industry.series[0].setData(industryTrendValue);
            }
        } else {
            if (num == 1) {
                //跳转具体地区
                c_highOpt_region.xAxis[0].categories = rname;
                c_highOpt_region.series[0].setData(rvalue);
            } else {
                //返回全国地区
                c_highOpt_region.xAxis[0].categories = regionTrendName;
                c_highOpt_region.series[0].setData(regionTrendValue);
            }
        }
    };
    var createDScoreTable = function () {
        var thstext = ["年份/维度"];
        var tdstext = [];
        for (var key1 in total) {
            var val = total[key1];
            var tds1 = [];
            for (var key2 in val) {
//年份 和 每一年总分
                tds1.push(key2);
                var oneyear = alldata[key2]["scores"];
                for (var key3 in oneyear) {
//每一年各个维度分数
                    if (thstext.indexOf(key3) == -1) {
                        thstext.push(key3);
                    }
                    tds1.push(oneyear[key3]);
                }
                tds1.push(val[key2]);
                tdstext.push(tds1);
            }
        }
        thstext.push("总分");
        var trs = $("<tr class='table_tr'></tr>"),
            tabth, tabtr;
        for (var i = 0, len = thstext.length; i < len; i++) {
            var td1 = $("<th class='table_th'></th>").append(thstext[i]);
            tabth = trs.append(td1);
        }
        tables.append(tabth);
        for (var l = 0, lenl = tdstext.length; l < lenl; l++) {
            trs = $("<tr class='table_tr'></tr>");
            var onetd = tdstext[l];
            for (var m = 0, lenm = onetd.length; m < lenm; m++) {
                var td2 = $("<td class='table_td'></td>").append(onetd[m]);
                tabtr = trs.append(td2);
            }
            trs = $("<tr class='table_tr'></tr>");
            tables.append(tabtr);
        }
    };
    var tables = $("#detailscores");
    if ($("#detailscores tr").length == 0) {
        createDScoreTable();
    }
};
function financialAnalysis(data) {
    var finance = data["finance"],
        financeRate = data["financeRate"],
        customs = data["customs"];
    var financialText = [
        "一、营业收入", "减：营业成本", "营业税金及附加", "营业费用", "管理费用", "财务费用", "资产减值损失", "加：公允价值变动收益", "投资收益", "二、营业利润",
        "加：营业外收入", "减：营业外支出", "三、利润总额", "减：应纳税所得额", "四、净利润", "资产总额"];
    var rateText = [
        "毛利率（%）", "营业利润率（%）", "净利润率（%）", "资产回报率（%）", "营业收入增长率（%）", "营业利润增长率（%）", " 净利润增长率（%）"
    ];
    var customText = [
        "进口", "出口"
    ];
    //----------------------财务图
    var finYear = [], finVal1 = [], finVal2 = [], finVal3 = [], finVal4 = [], finVal5 = [], finVal6 = [], finVal7 = [], finVal8 = [], finVal9 = [], finVal10 = [],
        finVal11 = [], finVal12 = [], finVal13 = [], finVal14 = [], finVal15 = [], finVal16 = [],
        finSRate1 = [], finSRate2 = [], finSRate3 = [], finSRate4 = [], finSRate5 = [], finSRate6 = [], finSRate7 = [], finSRate8 = [], finSRate9 = [], finSRate10 = [],
        finSRate11 = [], finSRate12 = [], finSRate13 = [], finSRate14 = [], finSRate15 = [], finSRate16 = [];
    for (var j in finance) {
        finYear.push(j);
        var dl = finance[j];
        var v1 = dl["revenue"], //营业收入
            v2 = dl["sales_cost"], //营业成本
            v3 = dl["sales_tax"], //营业税金及附加信息/核定征收企业经费支出
            v4 = dl["sales_expense"], //营业费用/核定征收企业换算收入总额
            v5 = dl["G_expense"], //管理费用
            v6 = dl["finance_expense"], //财务费用
            v7 = dl["asset_devaluation_losses"], //资产减值损失
            v8 = dl["fair_value_change"], //公允价值变动收益
            v9 = dl["investment_income"],//投资收益
            v10 = dl["operation_profit"], //营业利润
            v11 = dl["non_operating_income"], //营业外收入
            v12 = dl["non_operating_expense"], //营业外支出
            v13 = dl["total_profit"], //利润（亏损）总额
            v14 = dl["incometax_actual"], //实际应纳税所得额
            v15 = v13 - v14,    //净利润
            v16 = dl["assets_re"];//资产总额（矫正后）
        finVal1.push(v1);
        finVal2.push(v2);
        finVal3.push(v3);
        finVal4.push(v4);
        finVal5.push(v5);
        finVal6.push(v6);
        finVal7.push(v7);
        finVal8.push(v8);
        finVal9.push(v9);
        finVal10.push(v10);
        finVal11.push(v11);
        finVal12.push(v12);
        finVal13.push(v13);
        finVal14.push(v14);
        finVal15.push(v15);
        finVal16.push(v16);
        //------------
        if (v1 >= 0) {
            var deno = v1;
            finSRate1.push(toFixNum(v1 / deno));
            finSRate2.push(toFixNum(v2 / deno));
            finSRate3.push(toFixNum(v3 / deno));
            finSRate4.push(toFixNum(v4 / deno));
            finSRate5.push(toFixNum(v5 / deno));
            finSRate6.push(toFixNum(v6 / deno));
            finSRate7.push(toFixNum(v7 / deno));
            finSRate8.push(toFixNum(v8 / deno));
            finSRate9.push(toFixNum(v9 / deno));
            finSRate10.push(toFixNum(v10 / deno));
            finSRate11.push(toFixNum(v11 / deno));
            finSRate12.push(toFixNum(v12 / deno));
            finSRate13.push(toFixNum(v13 / deno));
            finSRate14.push(toFixNum(v14 / deno));
            finSRate15.push(toFixNum(v15 / deno));
            finSRate16.push(toFixNum(v16 / deno));
        } else {
            $("#c_financial").hide();
        }
    }
    //财务图
    $('#c_financial').highcharts({
        chart: {
            type: 'column'
        },
        colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
        title: {
            text: '利润表垂直分析图'
        },
        xAxis: {
            categories: finYear
        },
        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: '百分比（%）'
            }
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.x + '</b><br/>' +
                    this.series.name + ': ' + this.y + "%";
            }
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },
        series: [{
            name: '营业成本',
            data: finSRate2,
            stack: 'sub'
        }, {
            name: '营业税金及附加',
            data: finSRate3,
            stack: 'sub'
        }, {
            name: '营业费用',
            data: finSRate4,
            stack: 'sub'
        }, {
            name: '管理费用',
            data: finSRate5,
            stack: 'sub'
        }, {
            name: '财务费用',
            data: finSRate6,
            stack: 'sub'
        }, {
            name: '资产减值损失',
            data: finSRate7,
            stack: 'sub'
        }, {
            name: '公允价值变动收益',
            data: finSRate8,
            stack: 'add'
        }, {
            name: '投资收益',
            data: finSRate9,
            visible: false,
            stack: 'add'
        }, {
            name: '营业外收入',
            data: finSRate11,
            visible: false,
            stack: 'add'
        }, {
            name: '营业外支出',
            data: finSRate12,
            visible: false,
            stack: 'sub'
        }, {
            name: '所得税费用',
            data: finSRate14,
            visible: false,
            stack: 'sub'
        }, {
            name: '营业收入',
            data: finSRate1,
            color: 'rgba(0, 0, 0,.1)',
            stack: 'add'
        }]
    });
    //财务面积图
    $('#c_financial_area').highcharts({
        chart: {
            type: 'area'
        },
        title: {
            text: '财务数据趋势分析图'
        },
        xAxis: {
            categories: finYear
        },
        yAxis: {
            title: {
                text: '万元'
            },
            labels: {
                formatter: function () {
                    return this.value / 10000;
                }
            }
        },
        tooltip: {
            shared: true,
            useHTML: true,
            headerFormat: '<small>{point.key}' + '</small><table>'
        },
        plotOptions: {
            area: {
                stacking: 'normal',
                lineColor: '#666666',
                lineWidth: 1,
                marker: {
                    lineWidth: 1,
                    lineColor: '#666666'
                }
            }
        },
        series: [{
            name: '营业收入',
            data: finVal1
        }, {
            name: '营业成本',
            data: finVal2
        }, {
            name: '营业税金及附加',
            data: finVal3
        }, {
            name: '营业费用',
            data: finVal4
        }, {
            name: '管理费用',
            data: finVal5
        }, {
            name: '财务费用',
            data: finVal6
        }, {
            name: '资产减值损失',
            data: finVal7
        }, {
            name: '公允价值变动收益',
            data: finVal8
        }, {
            name: '投资收益',
            data: finVal9,
            visible: false
        }, {
            name: '营业利润',
            data: finVal10,
            visible: false
        }, {
            name: '营业外收入',
            data: finVal11,
            visible: false
        }, {
            name: '营业外支出',
            data: finVal12,
            visible: false
        }, {
            name: '利润总额',
            data: finVal13,
            visible: false
        }, {
            name: '应纳税所得额',
            data: finVal14,
            visible: false
        }, {
            name: '净利润',
            data: finVal15,
            visible: false
        }, {
            name: '资产总额',
            data: finVal16,
            visible: false
        }]
    });
    //hideSeries("c_financial");
    //hideSeries("c_financial_area");
    var c_finOpt = $('#c_financial_area').highcharts().series;
    createBsTable("c_financial_table", c_finOpt, financialText, finYear, "名称/年份");
    var $finlatr = $("#c_financial_table tr:last-child");
    $finlatr.before("<tr class='dividertr'><td></td></tr>");
    //--------------------各种比率图
    var finRateYear = [], finRVal1 = [], finRVal2 = [], finRVal3 = [], finRVal4 = [], finRVal5 = [], finRVal6 = [], finRVal7 = [];
    for (var i in financeRate) {
        finRateYear.push(i);
        var dd = financeRate[i];
        finRVal1.push(toFixNum(dd["gross"]));//毛利率（%）
        finRVal2.push(toFixNum(dd["profit"]));//营业利润率（%）
        finRVal3.push(toFixNum(dd["profit_net"]));//净利润率（%）
        finRVal4.push(toFixNum(dd["asset_return"]));//资产回报率（%）
        finRVal5.push(toFixNum(dd["income_increase"]));//营业收入增长率（%）
        finRVal6.push(toFixNum(dd["profit_increase"]));//营业利润增长率（%）
        finRVal7.push(toFixNum(dd["profit_net_increase"]));//净利润增长率（%）
    }
    function toFixNum(num) {
        if (num == "") {
            return num;
        } else {
            if (Math.abs(num) < 0.005) {
                return parseFloat((num * 100).toFixed(3));
            } else {
                return parseFloat((num * 100).toFixed(2));
            }
        }
    }

    //财务指标
    $('#c_financial_rate').highcharts({
        title: {
            text: '财务指标趋势分析图',
            x: -20
        },
        xAxis: {
            categories: finRateYear
        },
        yAxis: {
            title: {
                text: '百分数 (%)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: '%'
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [{
            name: '毛利率（%）',
            data: finRVal1
        }, {
            name: '营业利润率（%）',
            data: finRVal2
        }, {
            name: '净利润率（%）',
            data: finRVal3
        }, {
            name: '资产回报率（%）',
            data: finRVal4
        }, {
            name: '营业收入增长率（%）',
            data: finRVal5
        }, {
            name: '营业利润增长率（%）',
            data: finRVal6
        }, {
            name: '净利润增长率（%）',
            data: finRVal7
        }]
    });
    //hideSeries("c_financial_rate");
    var c_finROpt = $('#c_financial_rate').highcharts().series;
    createBsTable("c_rate_table", c_finROpt, rateText, finYear, "财务比率");
    //}
    //----------------------进出口
    if (customs == "") {
        $("#tab_caiwu .report-box:nth-child(2)").hide();
    } else {
        var imports = customs[1], exports = customs[2], customsYear = [], cuExVal = [], cusImVal = [], cusImdata = [], cusExdata = [];
        var now = 2016;

        function getseriesdata(obj, id) {
            for (var o in obj) {
                var cu_year = now.toString().substr(0, 2) + o.substr(0, 2),
                    cu_mon = o.substr(2),
                    str = cu_year + "-" + cu_mon,//e.g.:2015-12
                    strtimr = Date.parse(str),
                    val = parseFloat(obj[o]),
                    midarr = [];
                midarr.push(strtimr);
                midarr.push(val);
                if (id == "exports") {
                    customsYear.push(str);
                    cuExVal.push(val);
                    cusExdata.push(midarr);
                } else {
                    cusImVal.push(val);
                    cusImdata.push(midarr);
                }
                midarr = [];
            }
        }

        getseriesdata(imports, "imports");
        getseriesdata(exports, "exports");
        //进出口
        $('#c_importers').highcharts('StockChart', {
            chart: {
                alignTicks: false
            },
            rangeSelector: {
                buttons: [{
                    type: 'year',
                    count: 1,
                    text: '年度'
                }, {
                    type: 'all',
                    text: '全部'
                }],
                selected: 1,
                inputEnabled: false
            },
            legend: {
                enabled: true,
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            tooltip: {
                xDateFormat: '%Y-%m'
            },
            xAxis: {
                labels: {
                    formatter: function () {
                        var vDate = new Date(this.value);
                        //alert(this.value);
                        return vDate.getFullYear() + "-" + (vDate.getMonth() + 1);
                    },
                    align: 'center'
                }
            },
            navigator: {
                xAxis: {
                    labels: {
                        formatter: function (e) {
                            return Highcharts.dateFormat('%Y-%m', this.value);
                        }
                    }
                }
            },
            series: [{
                type: 'column',
                name: '进口',
                data: cusImdata,
                dataGrouping: {
                    units: [[
                        'month', // unit name
                        [1] // allowed multiples
                    ]]
                }
            }, {
                type: 'column',
                name: '出口',
                data: cusExdata,
                dataGrouping: {
                    units: [[
                        'month', // unit name
                        [1] // allowed multiples
                    ]]
                }
            }, {
                type: 'spline',
                name: '进口',
                data: cusImdata,
                visible: false,
                dataGrouping: {
                    units: [[
                        'month', // unit name
                        [1] // allowed multiples
                    ]]
                }
            }, {
                type: 'spline',
                name: '出口',
                data: cusExdata,
                visible: false,
                dataGrouping: {
                    units: [[
                        'month', // unit name
                        [1] // allowed multiples
                    ]]
                }
            }]
        });
        customHide(2016);
        var ya = 2016;
        customHide(ya);
        //hideSeries("c_importers");
        var c_cusOpt = $('#c_importers').highcharts().series;
        createBsTable("c_importers_table", c_cusOpt, customText, customsYear, "名称/时间");
    }
//海关table一些处理
    function customHide(year) {
        var table = $("#c_importers_table");
        var th = $("#c_importers_table .table_th");
        var tr = $("#c_importers_table .table_tr");
        var td = $("#c_importers_table .table_td");
        th.hide();
        td.hide();
        var notic = $("#c_importers_table .cu_year");
        notic.text(year);
        for (var k = 0, len = th.length; k < len; k++) {
            var $this = $(th[k]);
            var thistext = $this.text();
            if (thistext.indexOf(year) != -1) {
                $this.show();
                for (var h = 0, lenh = tr.length; h < lenh; h++) {
                    var $thistr = $(tr[h]);
                    $thistr.children(".table_td").eq(k).show();
                }
            }
        }
        if (year >= now) {
            $("#nextyear").hide();
        } else {
            $("#nextyear").show();
        }
        if (year <= 2014) {
            $("#prevyear").hide();
        } else {
            $("#prevyear").show();
        }
    }

    $("#prevyear").click(function () {
        var cur = parseInt($("#c_importers_table .cu_year").text());
        customHide(cur - 1);
    });
    $("#nextyear").click(function () {
        var cur = parseInt($("#c_importers_table .cu_year").text());
        customHide(cur + 1);
    });
    function hideSeries(id) {
        var ser = $('#' + id).highcharts().series;
        var s = 0, len = ser.length;
        for (var n = 0; n < len; n++) {
            var othis = ser[n];
            var odata = othis.data;
            var odatalen = odata.length;
            if (odatalen == 0) {
                othis.update({showInLegend: false});
                s++;
            } else {
                var l = 0;
                for (var m = 0, lenm = odatalen; m < lenm; m++) {
                    var od = odata[m];
                    var ody = od.y;
                    if (!ody) {
                        l++;
                    }
                }
                if (l == odatalen) {
                    othis.update({showInLegend: false});
                    s++;
                }
            }
        }
        if (s == len) {
            if (id == "c_importers") {
                $("#" + c_importers).hide();
            }
            if (id == "c_financial") {
                $("#c_financial_table").hide();
            }
            if (id == "c_financial_rate") {
                $("#c_rate_table").hide();
            }
        }
        if ($("#c_rate_table").css("display") == "none" && $("#c_financial_table").css("display") == "none") {
            $("#tab_caiwu .report-table-hide").hide();
        }
    }

    function createBsTable(id, opt, text, year, head) {
        var tables = $("#" + id);
        var trs = $("<tr class='table_tr'></tr>"),
            tabth, tabtr;
        //th标题
        for (var i = 0, len = year.length; i < len; i++) {
            var td1 = $("<th class='table_th'></th>").append(year[i]);
            tabth = trs.append(td1);
        }
        var fText = $("<th></th>").append(head);
        tabth.prepend(fText);
        tables.append(tabth);
        //tr每一行内容
        for (var l = 0, lenl = text.length; l < lenl; l++) {
            var td3 = $("<td></td>").append(text[l]);
            trs = $("<tr class='table_tr'></tr>").append(td3);
            var onetd = opt[l].yData;///////////////////
            for (var m = 0, lenm = onetd.length; m < lenm; m++) {
                var num = onetd[m];
                if (num) {
                    num = num.toLocaleString("en-US");
                }
                var td2 = $("<td class='table_td'></td>").append(num);
                tabtr = trs.append(td2);
            }
            trs = $("<tr class='table_tr'></tr>");
            tables.append(tabtr);
        }
        if (id == "c_importers_table") {
            customHide(now);
        }
    }
}
//海关进出口商品详情
function imdetailtab(datas) {
    var detailtable = $("#c_importers_detail_table");
    for (var key in datas) {
        var val = datas[key];
        var len = Object.keys(val).length;
        for (var k in val) {
            var val2 = val[k];
            var tr = $("<tr class='table_tr'><td class='table_td detail_year'>" + key + "</td><td class='table_td'>" + k + "</td><td class='table_td'>" + val2[0] + "</td><td class='table_td'>" + val2[1] + "</td></tr>");
            detailtable.append(tr);
        }
        var years = $("#c_importers_detail_table .detail_year");
        years.each(function (index) {
            if (index == 0) {
                $(this).attr("rowspan", len).removeClass("detail_year table_td").addClass("table_year");
            } else {
                $(this).remove();
            }
        })
    }
    $(".table_year").parent(".table_tr").prev(".table_tr").addClass("tr_border");
}